package com.thread.testfromvectortoqueue;

import java.util.Objects;
import java.util.Queue;
import java.util.Vector;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author: mayu
 * @date: 2021年04月14日 15:13
 */
public class TicketSeller4 {
    static Queue<String> tickets = new ConcurrentLinkedQueue<>();

    static {
        for (int i = 0; i < 1000; i++) {
            tickets.offer("票编号：" + i);
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                while (true) {
                    String poll = tickets.poll();
                    if (Objects.isNull(poll)) {
                        break;
                    } else {
                        System.out.println("销售了--" + poll);
                    }
                }
            }).start();
        }
    }
}
